﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;

namespace Common.Constants.Helper
{
    public class ConstantHelper
    {
        public static IList<String> GetConstantValue(Type type)
        {
            IList<String> result = new List<String>();

            foreach (FieldInfo fi in type.GetFields())
            {
                if (!ReflectionHelper.HasAttribute(fi, typeof(ConstantValueAttribute)))
                    continue;

                ConstantValueAttribute attr = fi.GetCustomAttributes(typeof(ConstantValueAttribute), false).First() as ConstantValueAttribute;
                
                if(attr.Description == null && fi.FieldType == typeof(String))
                    result.Add(fi.GetValue(null).ToString());
                else
                    result.Add(attr.Description);
            }

            return result;
        }
    }
}
